<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>原型链</title>
</head>
<body>
    <script>
        // 1 字面量
        var o1 = { name: 'o1' };
        var o2 = new Object({ name: 'o2' });

        // 2 通过构造函数
        var M = function(name) {
            this.name = name;
        }
        var o3 = new M('o3');

        console.log(o3.constructor === M); // true
        console.log(o3.constructor === Object); // false

        console.log(o3 instanceof M);  // true
        console.log(o3 instanceof Object);  // true
        console.log(o3.__proto__ === M.prototype);  // true
        console.log(M.prototype.__proto__ === Object.prototype);  // true

        console.log(o3);
        console.log(o3.constructor === M);  // true
        console.log(o3.__proto__ === M.prototype);  // true
        console.log(M.prototype.constructor === M)  // true

        // 3 Object.create()
        var p = { name: 'o4' };
        var o4 = Object.create(p);

        console.log(o1, o2)
        console.log(o3)
        console.log(o4)
    </script>
</body>
</html>